<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="/res/layui/css/layui.css">
  <style type="text/css">
    .container {
      width: 420px;
      height: 360px;
      min-height: 320px;
      max-height: 360px;
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      margin: auto;
      padding: 20px;
      z-index: 130;
      border-radius: 8px;
      background-color: #fff;
      box-shadow: 0 3px 18px rgba(100, 0, 0, .5);
      font-size: 16px;
    }

    .layui-input {
      border-radius: 5px;
      width: 300px;
      height: 40px;
      font-size: 15px;
    }

    .layui-form-item {
      margin-left: -20px;
    }

    .layui-btn {
      margin-left: -50px;
      border-radius: 5px;
      width: 350px;
      height: 40px;
      font-size: 15px;
    }

    .font-set {
      font-size: 13px;
      text-decoration: none;
      margin-left: 45%;
    }

    a:hover {
      text-decoration: underline;
    }

  </style>
</head>
<body>
<form class="layui-form" action="/login" method="post">
  <div class="container">
    <h2 style="text-align: center;margin-top: 15px;margin-bottom: 20px;">注册</h2>

    <div class="layui-form-item">
      <label class="layui-form-label">用户名</label>
      <div class="layui-input-block">
        <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名"
               autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">密 &nbsp;&nbsp;码</label>
      <div class="layui-input-inline">
        <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
               autocomplete="off" class="layui-input">
      </div>
      <!-- <div class="layui-form-mid layui-word-aux">辅助文字</div> -->
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">确认密码</label>
      <div class="layui-input-inline">
        <input type="password" name="password1" required lay-verify="required" placeholder="再次输入密码"
               autocomplete="off" class="layui-input">
      </div>
      <!-- <div class="layui-form-mid layui-word-aux">辅助文字</div> -->
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">邮箱</label>
      <div class="layui-input-block">
        <input type="text" name="username" required lay-verify="required|email" placeholder="请输入邮箱"
               autocomplete="off" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即注册</button>
      </div>
    </div>
    <a href="/login" class="font-set">返回登录</a>
  </div>
</form>
<script type="text/javascript" src="/res/layui/layui.js"></script>
<script>
  layui.use(['form', 'layer', 'jquery'], function () {
    var form = layui.form
    var layer = layui.layer
    var $ = layui.jquery

    //监听提交
    form.on('submit(formDemo)', function (data) {
      $.ajax({
        data: data.field,
        url: "/login",
        type: "post",
        success(data) {
          if (data.code != 0) {
            layer.msg(data.message)
          } else {
            window.location.href = '/admin/index'
          }
        }
      })
      return false;
    });
  });
</script>
</body>
</html>
